package main

import (
	RR "crypto/rand"
	"fmt"
	"github.com/nosixtools/solarlunar"
	"github.com/nosixtools/solarlunar/festival"
	"math"
	"math/big"
	"math/rand"
	"strconv"
	"strings"
	"time"
)

func BubbleSort(arr []int) []int{
	for i := 0; i < len(arr)-1; i++ {
		for j := 0; j < len(arr)-i-1; j++ {
			if arr[j] < arr[j+1] {
				//temp := arr[j]
				//arr[j] = arr[j+1]
				//arr[j+1] = temp

				arr[j], arr[j+1] = arr[j+1], arr[j]
			}
		}
	}
	return arr
}

func SelectSort(arr []int) []int{
	for i := 0; i < len(arr)-1; i++ {
		min_index := i
		for j := i + 1; j < len(arr); j++ {
			if arr[i] > arr[j] {
				min_index = j
			}
		}
		temp := arr[i]
		arr[i] = arr[min_index]
		arr[min_index] = temp
	}
	return  arr
}

func RangeRand(min, max int64) int64 {
	if min > max {
		panic("the min is greater than max!")
	}

	if min < 0 {
		f64Min := math.Abs(float64(min))
		i64Min := int64(f64Min)
		result, _ := RR.Int(RR.Reader, big.NewInt(max+1+i64Min))

		return result.Int64() - i64Min
	} else {
		result, _ := RR.Int(RR.Reader, big.NewInt(max-min+1))
		return min + result.Int64()
	}
}

func SubMonth(t1, t2 time.Time) (month int) {
	y1 := t1.Year()
	y2 := t2.Year()
	m1 := int(t1.Month())
	m2 := int(t2.Month())
	d1 := t1.Day()
	d2 := t2.Day()

	yearInterval := y1 - y2
	// 如果 d1的 月-日 小于 d2的 月-日 那么 yearInterval-- 这样就得到了相差的年数
	if m1 < m2 || m1 == m2 && d1 < d2 {
		yearInterval--
	}
	// 获取月数差值
	monthInterval := (m1 + 12) - m2
	if d1 < d2 {
		monthInterval--
	}
	monthInterval %= 12
	month = yearInterval*12 + monthInterval
	return
}

func main(){
	fmt.Println("时间：", time.Now().Format("2006-01-02"))
	fmt.Println("时间：", time.Now().AddDate(0,0,-10).Format("2006-01-02 15:04:05"))
	fmt.Println("时间：", time.Now().AddDate(1,0,-0).Format("2006-01-02 15:04:05"))
	fmt.Println("时间：", time.Now().AddDate(0,2,-0).Format("2006-01-02"))

	fmt.Println("时间 年/月：", time.Now().AddDate(0,2,-0).Format("2006-01"))

	var list = []int{1,35,86,24,75,54,76,86,86,86}
	fmt.Println("选择排序：", SelectSort(list))
	fmt.Println("冒泡排序：", BubbleSort(list))

	fmt.Println(12/5)

	fmt.Println(time.Now().Sub(time.Now().AddDate(0,0,-100)).Hours()/24)

	fmt.Println(time.Now().Sub(time.Now().AddDate(0,0,-100)))

	hh, _ := time.ParseDuration("4h")
	fmt.Println("时间：", time.Now().Add(hh))

	v := "fdsnff,yrt,ytrutyur,wrr435,645647,"
	fmt.Println(strings.Split(v, ","))

	fmt.Println(time.Now().Year())

	fmt.Println(time.Now().Month().String())



	fmt.Println("时间 年/月：", time.Now().AddDate(0,0,18).Format("2006-01-02"))


	fmt.Println(time.Now().Month(), time.Now().Year(), time.Now().Day())

	cd, _ := time.Parse("2006-01", time.Now().Format("2006-01"))
	im, _ := strconv.Atoi(cd.Month().String())
	fmt.Println(time.Now().Month().String())
	fmt.Println("时间 月：", im)

	s := "fesgrgfh"
	fmt.Println(s[0:2])


	fmt.Println("--------------------------------------------------------------------------")
	now := time.Now()
	currentYear, currentMonth, _ := now.Date()
	currentLocation := now.Location()

	firstOfMonth := time.Date(currentYear, currentMonth, 1, 0, 0, 0, 0, currentLocation)
	lastOfMonth := firstOfMonth.AddDate(0, 1, -1)

	lastOfMonth15 := time.Now().AddDate(0, 0, 14)

	fmt.Println("本月第一天:", firstOfMonth.Format("2006-01-02"))
	fmt.Println("本月最后一天:", lastOfMonth.Format("2006-01-02"))

	fmt.Println("距今15天:", lastOfMonth15.Format("2006-01-02"))

	fmt.Println("--------------------------------------------------------------------------")
	fmt.Println(time.Now().Weekday().String())


	fmt.Println("--------------------------------------------------------------------------")
	now1 := time.Now()

	offset := int(time.Monday - now1.Weekday())
	if offset > 0 {
		offset = -6
	}

	weekStartDate := time.Date(now.Year(), now1.Month(), now1.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
	weekMonday := weekStartDate.Format("2006-01-02")
	fmt.Println("本周周一:", weekMonday)

	fmt.Println("--------------------------------------------------------------------------")
	solarDate := time.Now().Format("2006-01-02")
	fmt.Println(solarlunar.SolarToChineseLuanr(solarDate))
	fmt.Println(solarlunar.SolarToSimpleLuanr(solarDate))

	fmt.Println("--------------------------------------------------------------------------")
	lunarDate := "1990-04-12"
	fmt.Println(solarlunar.LunarToSolar(lunarDate, false))

	fmt.Println("--------------------------------------------------------------------------")
	festival := festival.NewFestival("E:/gowork/allTestUtil/festival.json")
	fmt.Println("2020-08-15：", festival.GetFestivals("2020-08-15"))


	fmt.Println("--------------------------------------------------------------------------")

	for i := 0; i < 10; i++ {
		data1 := RangeRand(2, 20)
		data2 := rand.Float32()
		data := float32(data1) + data2
		fmt.Println(data)
	}

	fmt.Println("--------------------------------------------------------------------------")
	fmt.Println(5/8)

	fmt.Println("--------------------------------------------------------------------------")
	fmt.Println("上月第一天:", time.Now().AddDate(0, -1, -time.Now().Day() + 1).Format("2006-01-02"))

	fmt.Println("--------------------------------------------------------------------------")
	wv := "fdsnff"
	fmt.Println(strings.Split(wv, ","))



	fmt.Println("--------------------------------------------------------------------------******")

	t , _ := time.Parse("2006-01-02 15:04:05", "2020-07-15 09:43:01")

	fmt.Println(t)

	fmt.Println(time.Now())

	fmt.Println(t.Sub(time.Now()))

	fmt.Println(t.Sub(time.Now()).Minutes())

	fmt.Println(time.Now().Sub(t).Minutes())

	fmt.Println(time.Now().Add(time.Minute * 1))

	fmt.Println(time.Now().Sub(time.Now().Add(time.Minute * 1)))

	var x int = -3
	fmt.Println(x)


	fmt.Println("--------------------------------------------------------------------------******")
	fmt.Println(rand.Intn(3))


	fmt.Println("--------------------------------------------------------------------------******")
	beOverdueTime := time.Now().AddDate(0, 3, 0)
	newNow := time.Now()

	fmt.Println(beOverdueTime.After(newNow))
	fmt.Println(beOverdueTime.Before(newNow))



	fmt.Println("--------------------------------------------------------------------------******")
	reminderTime, _ := time.Parse("15:04:05", "17:18:00")

	rnow, _ := time.Parse("15:04:05", time.Now().Format("15:04:05"))

	fmt.Println(reminderTime.Before(rnow))



	fmt.Println("--------------------------------------------------------------------------******")

	hhh ,_ := time.ParseDuration("4h")
	fmt.Println(hhh)
	fmt.Println(time.Now().Add(hhh).Format("2006-01-02 15:04:05"))



	fmt.Println("时间 年/月：", time.Now().AddDate(0,0,-7).Format("2006-01-02"))


	fmt.Println(time.Now().AddDate(0, 1,0).Format("2006-01"))

	fmt.Println("--------------------------------------------------------------------------******")

	loadLocation, _ := time.LoadLocation("Asia/Shanghai")
	tt, _ := time.ParseInLocation("2006-01-02 15:04:05", "2020-08-30 12:00:00", loadLocation)


	//tt, _ := time.Parse("2006-01-02 15:04:05", "2020-08-30 12:00:00")
	//tt1, _ := time.Parse("2006-01-02 15:04:05", "2020-08-30 16:00:00")

	fmt.Println(time.Now())
	fmt.Println(tt)

	fmt.Println(time.Now().After(tt))

	fmt.Println("--------------------------------------------------------------------------******")
	n, _ := strconv.Atoi("08")
	fmt.Println(n)

	l := len("hfdhfdsbgfdhh")
	fmt.Println("l：", l)

	var klist []int
	println(&klist)
}

type Father interface {
	animals(int, string) string
	plants(int, string) string

}

type son struct {

}

//实现接口方法
func (s *son) animals(code int, animal string) string {
	return animal
}

func (s *son) plants(code int, plant string) string {
	return plant
}

